package com.zlkj.pro.modular.admin.service.impl;

import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlkj.pro.core.util.ConvertUtil;
import com.zlkj.pro.modular.admin.entity.Config;
import com.zlkj.pro.modular.admin.entity.User;
import com.zlkj.pro.modular.admin.mapper.UserMapper;
import com.zlkj.pro.modular.admin.model.dto.UserDTO;
import com.zlkj.pro.modular.admin.model.vo.UserVO;
import com.zlkj.pro.modular.admin.service.ConfigService;
import com.zlkj.pro.modular.admin.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UsersServiceImpl extends ServiceImpl<UserMapper, User> implements UsersService {

    @Resource
    ConfigService configService;

    @Autowired
    UsersService usersService;

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVO detail(UserDTO dto) {
        User user = baseMapper.selectById(dto.getUserId());
        Config config = configService.getOne(new LambdaQueryWrapper<Config>()
                .eq(Config::getName, "水印配置")
                .eq(Config::getCode, "SYS_SHUIYIN_CONFIG")
                .eq(Config::getDelFlag, YesOrNotEnum.N.getCode()));
        user.setStatusFlag(config.getStatusFlag());
        UserVO userVO = ConvertUtil.turn(user, UserVO.class);
        userVO.setValue(config.getValue());
        return userVO;
    }

}
